function setDisable(userId) {
    xhExtra.ajaxRequest('User/setUserState', {ids: [userId], target: 'disable'}, {}, function(result) {
        window.location.reload();
    });
}

function setContact(userId){
    xhExtra.ajaxRequest('hrm/Staff/staffContact', {staffId: xhTool.getQuery('staffId'), userId: userId}, {}, function(result) {
        window.location.reload();
    });
}

function disContact(userId) {
    xhExtra.ajaxRequest('hrm/Staff/staffContact/true', {staffId: xhTool.getQuery('staffId'), userId: userId}, {}, function(result) {
        window.location.reload();
    });
}

function addUser() {
    window.top.swal({
        titleText: '记录使用账号',
        html:'<input id="loginName" type="text" class="form-control" placeholder="账号"><br><textarea id="desc" rows="3" placeholder="备注" class="form-control"></textarea>',
        showCancelButton: true,
        cancelButtonText: '取消',
        confirmButtonText: '确认',
        showLoaderOnConfirm: true,
        preConfirm: function (text) {
            return new Promise(function (resolve, reject) {
                var loginName = $('#loginName', top.document).val();
                if (!loginName) {
                    reject('账号必填！');
                } else {
                    resolve(loginName);
                }
            })
        },
        allowOutsideClick: true
    }).then(function (loginName) {
        var desc = $('#desc', top.document).val();
        xhExtra.ajaxRequest('hrm/staff/saveStaffUser',{staffId:xhTool.getQuery('staffId'), loginName:loginName,desc:desc},{},function (res) {
            window.top.xhTop.showSuccess(res.msg);
            window.location.reload();
        })
    }, function(dismiss) {});
}

function deleteUser(id) {
    xhExtra.askChangeStatus('hrm/staff/delStaffUser',{id:id},null,'确认要删除嘛',function (res) {
        window.top.xhTop.showSuccess(res.msg);
        window.location.reload();
    })
}


$(function () {
    var sName = unescape(xhTool.getQuery('sName'));
    var sPhoneNum = xhTool.getQuery('sPhoneNum');
    var createAccountDom = window.top.xhTop.getModalConfirmDom();
    createAccountDom.click(function () {
        window.top.swal({
            title: '你确定要创建账号？',
            text: '姓名为：'+sName+'，账号为：'+sPhoneNum+',默认密码为：123456',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: '是的，我要创建',
            cancelButtonText: '不了，再考虑下'
        }).then(function() {
            xhExtra.ajaxRequest('hrm/staff/createAccount',{name:sName,phone:sPhoneNum},{},function (result) {
                if(result.code==200){
                    window.top.swal(
                        '创建成功',
                        '',
                        'success'
                    );
                    window.location.reload();
                }
                xhExtra.setBtnNormal(createAccountDom);
            });
        },function (dismiss) {
            if(dismiss=='cancel'){
                xhExtra.setBtnNormal(createAccountDom);
                return false;
            }
        });
    });
});